/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.j002.requirementengineeringmuni.impl;

import cz.muni.fi.j002.requirementengineeringmuni.Player;
import cz.muni.fi.j002.requirementengineeringmuni.Bank;
import cz.muni.fi.j002.requirementengineeringmuni.Game;
import cz.muni.fi.j002.requirementengineeringmuni.impl.BankImpl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

/**
 *
 * @author stefan
 */
public class PlayerImpl implements Player {

    private Bank bank;
    private String name;
    private BigDecimal defaultBid = Player.DEFAULT_BID;
    private List<Game> bestGames;
    
    /**
     * Creates a new Player with an initial amount of Player.DEFAULT_INITIAL_AMOUNT and a provided name
     * @param name 
     */
    public PlayerImpl(String name) {
        this(DEFAULT_INITIAL_AMOUNT, name);
    }
    
    /**
     * Creates a new Player with a provided initial amount and name
     * @param name 
     */
    public PlayerImpl(BigDecimal initialAmount, String name) {
        
        if(null == name) {
            throw new IllegalArgumentException("Name must not be null");
        }
        if(name.isEmpty()) {
            throw new IllegalArgumentException("Name must be provided");
        }
        this.name = name;
        
        this.bank = new BankImpl(initialAmount);
        
        this.bestGames = new ArrayList<Game>();
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public BigDecimal getDefaultBid() {
        return defaultBid;
    }
    @Override
    public void setDefaultBid(BigDecimal defaultBid) {
        this.defaultBid = defaultBid;
    }
    
    @Override
    public Bank getBank() {
        return this.bank;
    }
    
    public static PlayerImpl newGuest() {
        return newGuest(DEFAULT_GUEST_NAME + "-" + new Random().nextInt(100));
    }

    public static PlayerImpl newGuest(String guestName) {
        return new PlayerImpl(DEFAULT_INITIAL_AMOUNT, guestName);
    }

    @Override
    public List<Game> getBestGamesRecords() {
        return Collections.unmodifiableList(bestGames);
    }

    @Override
    public boolean recordAGame(Game game) {
        for(Game bestGame : bestGames) {
            /* TODO: implement */
        }
        
        return false;
    }
    
    @Override
    public String toString() {
        return "PlayerImpl{" + "bank=" + bank + ", name=" + name + ", defaultBid=" + defaultBid + '}';
    }
    
}
